$j(document).ready(function () {
});





//显示操作按钮
function displayButtons(status){
	if(status == null){
		//case: 新增
		enableIconBtn("save");
		disableIconBtn("delete");
	}else{
		//case:编辑
		enableIconBtn("save");
		enableIconBtn("delete");
	}
	
}	 


//验证函数
function validateAction(){
	if(!validateCustomer($('tab-profile'))){
		return false;
	}	
	if($j('#tab-profile #password').length > 0){
		if($j('#tab-profile #password').val()!=$j('#tab-profile  #confirmPassword').val()){
			alert(__FMT.customerDetail_password_twoField);
			$j('#tab-profile #confirmPassword').val("").focus();
			return false
		}	
	}
	return true;
}
//保存
function saveCustomer(){
	if(!validateAction()){
    	return ;
    }
    var postData="";
    postData += $j('#tab-profile :input').serialize();
    var url=$j('#customer').attr('action')+"?doAction=save";
    $j.post(url,postData,saveCustomerCallback,"json");
}
//保存回调函数
function saveCustomerCallback(data){
	if(data.error){
		sysMsg(data.error,true);
		return;
	}
	
	refreshParent();
	returnToList();
	sysMsg(__FMT.customerForm_saveCustomer_success);
}


// 删除
function deleteCustomer(){
	var entityName = $j("#username").html();
	if (confirm(__FMT.common_message_confirmDeleteThis + " " + entityName + "?")) {
		var paraData = {
			customerId: $j("#customerId").val()
		};
		$j.post(__ctxPath + "/customer/customer/blank.html?doAction=delete", paraData, deleteCustomerCallback,"json");
	}
}
//删除回调函数
function deleteCustomerCallback(data){
	sysMsg(data.msg);
	refreshParent();
	returnToList();
}

//从Form返回到list
function returnToList(){
	$j('#formDiv').hide();
	$j('#mainDiv').show();
}


//刷新父窗口的产品列表
function refreshParent(){
	refreshCustomerList();
}

//订单 分页
function fnOnGoToPageSalesOrder(){
	var postData = $j('#tab-salesOrder :input').serializeArray();
	url=__ctxPath+"/customer/customer/blank.html?&doAction=getSalesOrderList";
	$j("#tab-salesOrder").loading().load(url,postData);  
}

//积分历史 分页
function fnOnGoToPageShopPointHistory(){
	var postData = $j('#list-shopPointHistory :input').serializeArray();
	url=__ctxPath+"/customer/customer/blank.html?&doAction=getShopPointHistoryList";
	$j("#list-shopPointHistory").loading().load(url,postData);  
}

//调整积分
function adjustShopPoint(){
	applyValidate($('amount'),"required,intRange=[0-100000]");
	applyValidate($('description'),"required,maxlength=500");
	if(validateForm($('pointInfoForm'))){
		var postData  = $j("#pointInfoForm :input").serializeArray();
		$j.post(__ctxPath + "/customer/customer/blank.html?doAction=adjustShopPoint", postData, adjustShopPointCallback,"json");
	}else{
		jAlert(__vaMsg.notPass);
	}
}

//调整积分callback
function adjustShopPointCallback(data){
	if(data.result){
		alert(__FMT.customerDetail_adjustShopPoint_success);
	}else{
		alert(__FMT.customerDetail_adjustShopPoint_false);
	}
	$j('#tab-shopPoint').loading().load(__ctxPath + "/customer/customer/blank.html?doAction=loadShopPointTab&customerId="+data.customerId);
}

//评论 分页
function fnOnGoToPageReview(){
	var postData = $j('#tab-review :input').serializeArray();
	url=__ctxPath+"/customer/customer/blank.html?&doAction=getReviewList";
	$j("#tab-review").loading().load(url,postData);  
}

//咨询 分页
function fnOnGoToPageConsult(){
	var postData = $j('#tab-consult :input').serializeArray();
	url=__ctxPath+"/customer/customer/blank.html?&doAction=getConsultList";
	$j("#tab-consult").loading().load(url,postData);  
}

//反馈 分页
function fnOnGoToPageFeedback(){
	var postData = $j('#tab-feedback :input').serializeArray();
	url=__ctxPath+"/customer/customer/blank.html?&doAction=getFeedbackList";
	$j("#tab-feedback").loading().load(url,postData);  
}

//收货人地址 分页
function fnOnGoToPageAddress(){
	var postData = $j('#tab-address :input').serializeArray();
	url=__ctxPath+"/customer/customer/blank.html?&doAction=getAddressList";
	$j("#tab-address").loading().load(url,postData);  
}